package com.gxa.controller;

import com.gxa.service.impl.LoginServiceImpl;
import com.gxa.utils.JWTUtils;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "登录管理控制器")
@ResponseBody
public class LoginController {

    @Autowired
    private LoginServiceImpl loginService;

    @PostMapping("/login")
    @ApiOperation("登录")
    public ResponseData login(@ApiParam(value = "登录用户名",required = true) String name, @ApiParam(value = "登录密码",required = true) String password){
//        System.out.println(name);
//        System.out.println(password);
//        System.out.println(loginService.login(name,password).toString());
        if(loginService.login(name, password)!=null){
            //生成token
            String token = JWTUtils.sign(name, password);

            return new ResponseData(1,"登录成功",token);
        }else{
            return new ResponseData(0,"登陆失败");
        }
    }
}
